package org.rsbot.util;

import java.awt.Component;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.TrayIcon.MessageType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Minimizer
{
  private static TrayIcon icon;
  private static Component comp;
  private static SystemTray tray;

  private static Image getImage()
    throws HeadlessException
  {
    Image localImage = GlobalConfiguration.getImage("/resources/images/icon.png", GlobalConfiguration.Paths.ICON);

    return localImage;
  }

  private static PopupMenu createPopupMenu()
    throws HeadlessException
  {
    PopupMenu localPopupMenu = new PopupMenu();

    MenuItem localMenuItem1 = new MenuItem("Release from Tray");

    localMenuItem1.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        Minimizer.comp.setVisible(true);
        SystemTray.getSystemTray().remove(Minimizer.icon);
        Minimizer.access$102(null);
      }
    });
    localPopupMenu.add(localMenuItem1);
    MenuItem localMenuItem2 = new MenuItem("Exit Bot");

    localMenuItem2.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        System.exit(0);
      }
    });
    localPopupMenu.add(localMenuItem2);

    return localPopupMenu;
  }

  public static void snapToTray(Component paramComponent)
    throws Exception
  {
    comp = paramComponent;
    tray = SystemTray.getSystemTray();

    icon = new TrayIcon(getImage(), "Rsbot", createPopupMenu());

    icon.addActionListener(new ActionListener(paramComponent)
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        this.val$c.setVisible(true);
        Minimizer.tray.remove(Minimizer.icon);
      }
    });
    tray.add(icon);
  }

  public static void displayMessage(Object paramObject, TrayIcon.MessageType paramMessageType)
  {
    String str = null;
    switch (4.$SwitchMap$java$awt$TrayIcon$MessageType[paramMessageType.ordinal()]) {
    case 1:
      str = "Information";
      break;
    case 2:
      str = "Error !";
      break;
    case 3:
      str = "Warning !";
    }

    icon.displayMessage(str, paramObject.toString(), paramMessageType);
  }
}